package com.net.xpay.web.controller.merchant;

import com.google.common.base.Preconditions;
import com.net.xpay.web.vo.UserBusinessAuthVo;
import com.net.common.model.ResultData;
import com.net.xpay.common.domain.User;
import com.net.xpay.common.domain.UserBusinessAuth;
import com.net.xpay.common.manager.UserBusinessAuthManager;
import com.net.xpay.common.service.UserBusinessAuthService;
import com.net.xpay.core.model.UserBusinessAuthModel;
import com.net.xpay.core.utils.BeanCopierUtil;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
@RestController
@RequestMapping("/merchant/user-business-auth")
@Api(tags = "公共/企业实名认证", description = "公共 企业实名认证 net")
@Slf4j
public class UserBusinessAuthController {

    @Autowired
    private UserBusinessAuthService userBusinessAuthService;

    @Autowired
    private UserBusinessAuthManager userBusinessAuthManager;
    /**
     * 企业实名认证
     */
    @ApiOperation("企业实名认证")
    @PostMapping("/submit-business-authentication")
    public ResultData<Boolean> submitUserBusinessAuthentication(@ApiIgnore @RequestUser User merchant, @RequestBody UserBusinessAuthModel model)  {
        Preconditions.checkArgument(model != null);
        userBusinessAuthService.submitBusinessAuthentication(merchant,model);
        return new ResultData<>(true);
    }

    /**
     * 查询实名认证信息
     */
    @ApiOperation("查询实名认证信息")
    @PostMapping("/get-info")
    public ResultData<UserBusinessAuthVo> getByUserBusinessAuthId(@ApiIgnore @RequestUser User merchant)  {
        Long userId = merchant.getId();
        UserBusinessAuth userBusinessAuth = userBusinessAuthManager.getByUserId(userId);
        if (userBusinessAuth == null ){
            return new ResultData<>(null);
        }else {
            UserBusinessAuthVo vo = new UserBusinessAuthVo();
            BeanCopierUtil.copy(userBusinessAuth,vo);
            vo.setCheckCode("");
            return new ResultData<>(vo);
        }

    }

    /**
     * 修改实名认证信息
     */
    @ApiOperation("修改实名认证信息")
    @PostMapping("/update-info")
    public ResultData<Boolean> updateUserBusinessAuth(@ApiIgnore @RequestUser User merchant,  Long id)  {
        userBusinessAuthService.updateUserBusinessAuth(merchant,id);

        return new ResultData<>(true);
    }
}
